package com.bysj.yqsht.web.controller;

import com.bysj.yqsht.bean.extend.Login;
import com.bysj.yqsht.service.IAccountService;
import com.bysj.yqsht.utils.Message;
import com.bysj.yqsht.utils.MessageUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/user")
@Api(description = "登录接口")
public class LoginsController {
    @Autowired
    private IAccountService accountService;

    @PostMapping("/login")
    public Message login(@RequestBody Login login){
//        System.out.println("巴啦啦小魔仙："+login.getUsername()+login.getPassword());
        String token = accountService.login(login.getUsername(),login.getPassword());
        return MessageUtil.success("登录成功",token);
    }

    @GetMapping("/info")
    public Map info() {
        HashMap<String, Object> responseInfo = new HashMap<>();
        HashMap<String, Object> responseData = new HashMap<>();
        responseData.put("roles","admin");
        responseData.put("name","Super admin");
        responseData.put("avatar","\n" +
                "https://yqshtphoto.oss-cn-beijing.aliyuncs.com/850c6016a157e70eaa524f4663dbacca.jpg");
        responseInfo.put("status",200);
        responseInfo.put("msg","登录成功");
        responseInfo.put("data",responseData);
        return responseInfo;
    }
    @PostMapping("/logout")
    public Message logout() {
        return MessageUtil.success("退出成功");
    }
}
